
import React, { useEffect, useState } from "react"
import { comRequest } from '../../request'
import { Divider, Spin } from 'antd'
export const BDLinfo = ({ id, isSz, type, yhbdl }) => {
    const [bldOtherInfo, setBdlOtherInfo] = useState({})
    const [isLoading, setIsLoading] = useState(false)
    const getOtherBdlInfo = async () => {
        console.log("查询商品数据")

        setIsLoading(true)

        let cecid = isSz ? `12.${id}` : `10.${id}`
        const bdlOther = `
https://push2.eastmoney.com/api/qt/stock/get?invt=2&fltt=1&reqt=4&fields=f419%2Cf152%2Cf420%2Cf421%2Cf422&secid=${cecid}&ut=fa5fd1943c7b386f172d6893dbfba10b&wbp2u=%7C0%7C0%7C0%7Cweb&_=1729937534943`

        try {
            const result = await comRequest({
                url: bdlOther,
            })
            const formartBdlData = (obj) => {
                return {

                    d30
                        :
                        obj?.f419 / 100,
                    d60
                        :
                        obj?.f420 / 100,
                    d120
                        :
                        obj?.f421 / 100,
                    d240
                        :
                        obj?.f422 / 100,
                }
            }
            const data = result?.data?.data || {}
            console.log("对0", data)
            setIsLoading(false)

            setBdlOtherInfo(formartBdlData(data))
        } catch (error) {
            console.log("error", error)
            setIsLoading(false)

        }

    }
    useEffect(async () => {
        if (id) {
            getOtherBdlInfo()
        }

    }, [])

    const formartbdlColor = (value) => {
        if (value >= 40) {
            return 'red'
        }
        if (value < 40) {
            return 'green'
        }
        return ''
    }
    return <div>隐波：<span style={{
        color: formartbdlColor(yhbdl),
        fontSize: '26px'
    }}>
        {
            yhbdl
        }%
    </span>
        <Spin tip="Loading" size="small" spinning={isLoading}>
            <div>

                <span style={{
                    color: formartbdlColor(bldOtherInfo?.d30),
                    fontSize: '20px'
                }}>
                    30日：{
                        bldOtherInfo?.d30
                    }%</span>
                <Divider type='vertical' />
                <span style={{
                    color: formartbdlColor(bldOtherInfo?.d60),
                    fontSize: '20px'
                }}>
                    60日：{
                        bldOtherInfo?.d60
                    }%   </span>         <Divider type='vertical' />
                <span style={{
                    color: formartbdlColor(bldOtherInfo?.d60),
                    fontSize: '20px'
                }}>
                    120日：{
                        bldOtherInfo?.d120
                    } %    </span>
                <Divider type='vertical' />
                <span style={{
                    color: formartbdlColor(bldOtherInfo?.d240),
                    fontSize: '20px'
                }}>
                    240日：{
                        bldOtherInfo?.d240
                    }%  </span>
            </div>
        </Spin>

    </div>
}